package com.platform.modules.alg.alglib.poj2833;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Poj2833 {
    public String output = "";

    class MyComparator implements Comparator<Integer> {
        public int compare(Integer num1, Integer num2) {
            return num2.compareTo(num1);
        }
    }

    public String cal(String input) {
        int n1, n2, n, i, x;
        long sum;
        String[] line = input.split("\n");

        String[] words = line[0].split(" ");
        n1 = Integer.parseInt(words[0]);
        n2 = Integer.parseInt(words[1]);
        n = Integer.parseInt(words[2]);

        PriorityQueue<Integer> q1 = new PriorityQueue<>(new MyComparator()); // 最大值优先,保存最小的 n2 个
        PriorityQueue<Integer> q2 = new PriorityQueue<>(); // 默认为小顶堆,保存最大的 n1 个
        sum = 0;
        String[] numbers = line[1].split(" ");
        for (i = 0; i < n; i++) {
            x = Integer.parseInt(numbers[i]);
            sum += x;
            q1.add(x);
            q2.add(x);
            if (q1.size() > n2)
                q1.poll();
            if (q2.size() > n1)
                q2.poll();
        }
        while (!q1.isEmpty()) {
            sum -= q1.poll();
        }
        while (!q2.isEmpty()) {
            sum -= q2.poll();
        }
        output = String.format("%.6f", 1.0 * sum / (n - n1 - n2));
        return output;
    }
}
